#include <thread>
#include <future>
#include "common_log.hpp"

void ThreadFunction(std::promise<int> &prom, int id) {
    int count = 0;
    for (int i = 0; i < 10; ++i) {
        LOG_INFO("Thread(%d): Message %d", id, i);
        count++;
        std::this_thread::sleep_for(std::chrono::milliseconds(1));
    }
    if (id == 0) {
        count += 100;
    }
    prom.set_value(count);
}

int main() {
    std::promise<int> prom0;
    std::promise<int> prom1;

    std::thread t1(ThreadFunction, std::ref(prom0), 0);
    std::thread t2(ThreadFunction, std::ref(prom1), 1);

    std::future<int> ft0 = prom0.get_future();
    std::future<int> ft1 = prom1.get_future();

    int res0 = ft0.get();
    int res1 = ft1.get();

    LOG_INFO("res0(%d) --- res1(%d)", res0, res1);
    if (t1.joinable()) { t1.join(); }
    if (t2.joinable()) { t2.join(); }
    return 0;
}
